﻿using Infra_Common.redis;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using xiaodingmarket_application.Interfaces;
using xiaodingmarket_application.ViewModel;
using xiaodingmarket_Domain_core.Bus;
using xiaodingmarket_Domain_core.Notificatiions;

namespace xiaodingmarket_service.Controllers.Users
{
    [Authorize]
    public class UserController : ApiController
    {
        private readonly IManageService _manageService;
        private readonly IUserService _userService;
        private readonly RedisClient Redisclient;
        
        public UserController(IUserService userService,IManageService manageService,INotificationHandler<DomainNotification> notifications, IMediatorHandler mediator,RedisClient redisclient) : base(notifications, mediator)
        {
            Redisclient = redisclient;
            _manageService = manageService;
            _userService = userService;
        }
        /// <summary>
        /// 以前的用户创建接口
        /// </summary>
        /// <param name="commodityViewModel"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Policy = "CanBasicoperation")]
        [Route("User")]
        public IActionResult Post([FromBody]UserViewModel commodityViewModel)
        {
            if (!ModelState.IsValid)
            {
                NotifyModelStateErrors();
                return Response(commodityViewModel);
            }
            

            return Response(commodityViewModel);
        }
        /// <summary>
        /// 获取用户的资料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Policy = "CanBasicoperation")]
        [Route("customer-management/{id:guid}")]
        public IActionResult Get(Guid id)
        {
            var customerViewModel = _userService.GetById(id);

            return Response(customerViewModel);
        }


    }
}
